package group2assignone.ucm.administrator;

import group2assignone.ucm.UCController;
import group2assignone.view.administrator.AdminMainView;
import group2assignone.dao.*;
import group2assignone.model.*;
import group2assignone.ucm.UCStartup;
import java.lang.Object.*;
import java.util.*;

/**
 * Use Case: Admin Main VIew                                                <br>
 * Pre-condition: Administrator has logged in                               <br>
 * Post-condition: Admin Main View is run                                   <br>
 * 1. system retrieves the existing list of managers                                    <br>
 * 2. system runs Admin Main view                                     <br>

 * @author group2                                                           <br>
 */
public class UCUIAdminMainView implements UCController {

    private Administrator adm;
    private ArrayList<Manager> manList = new ArrayList<Manager>();
    private static final int LIST = 70;
    private static UCUIAdminMainView instance;
    private MyDAO coms;

    private UCUIAdminMainView() {
     coms = UCStartup.getInstance().getDAO();
    }

    public static UCUIAdminMainView getInstance() {
        if (instance == null) {
            instance = new UCUIAdminMainView();
        }
        return instance;
    }

    public void setAdministrator(Administrator adm) {
        this.adm = adm;
    }

    @Override
    public void run() {
        //1. system retrieves the existing list of managers
        manList = coms.sQLGetAllFromManager();
        //2. system runs Admin Main view
        AdminMainView gui = new AdminMainView(manList, adm);
        gui.go();
    }


    //TESTING FUNCTION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    private void createDummyList() {
        for (int i = 0; i < LIST; i++) {
            Manager m = new Manager();
            m.setUsername("usernam" + i);
            m.setFName("fName" + i);
            m.setLName("lastNme" + i);
            m.setPassword("paswrdsss" + i);
            m.setDob("01/10/2001" + i);
            manList.add(m);
        }
    }
}